//
//  PostDetailsViewController.m
//  唧歪
//
//  Created by ZC on 15/7/10.
//  Copyright (c) 2015年 MWJ. All rights reserved.
//

#import "PostDetailsViewController.h"
#import "AllCommentViewController.h"  //所有评论回复界面
#import "pictureDetailViewController.h"  //全部图片界面
#import "Comment.h"
#import "commCell.h"
#import "AppDelegate.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import <AVFoundation/AVFoundation.h>
#import "ImageCompression.h"
#import "picbig.h"

#define PostdetailsURL @"https://app.jiwaipro.com:8888/index.php/JiWai/postAccording"  //帖子详情
#define commentURL @"https://app.jiwaipro.com:8888/index.php/JiWai/comment"  //评论加载
#define commentcountURL @"https://app.jiwaipro.com:8888/index.php/JiWai/addtimeandcount"  //评论数和显示时间url
#define commentImageURL @"https://app.jiwaipro.com:8888/index.php/JiWai/uploadCommentImage"  //图片评论url
#define newsURL @"https://app.jiwaipro.com:8888/index.php/JiWai/news"  //信息提醒
#define DSURL @"https://app.jiwaipro.com:8888/index.php/JiWai/ds"  //打赏
#define audioURL @"https://app.jiwaipro.com:8888/index.php/JiWai/uploadcommentaudio"
#define myFocuscancelURL @"https://app.jiwaipro.com:8888/index.php/JiWai/cancelfocus"
#define myFocusURL @"https://app.jiwaipro.com:8888/index.php/JiWai/focus"

@interface PostDetailsViewController (){
    AppDelegate *app;
    NSMutableArray *postdetailsArray;
    NSMutableArray *postimageArray;
    NSMutableArray *commentArray;
    NSMutableArray *commentArray1;
    NSMutableArray *commentArray2;
    int keyboard;
    NSString *currentTime;
    NSString *strIdentifier;
    NSString *strIdentifier1;
    UIAlertView *_alert;
    NSString *contentStr;
    NSMutableArray *commentstr;
    NSString *showTimeStr;
    NSString *commcount;
    NSString *Content;
    NSString *messageTag;
    UIImage *img;
    Comment *c;
    NSString *commentID;
    NSString *audiopath;
    commCell *cell;
    NSString *userid;
    NSString *usernews;
    NSString *DSStr;
    int aaaa;
    int bbbb;
    NSString *audioTime;
    UIImageView *imgView;
    int imgcount;
    int index;
    int allCount;
    NSMutableArray *imageArray;
    UIScrollView *bigScroll;
    UIImageView *wf;
    UIView *bigView;
    NSString *contentText;
    NSMutableArray *allImageArray;
    NSString *newviewStr;
    NSURL *recordUrl;
    NSMutableArray *focusArray;
    NSString *focusStr;
    NSString *news_content;
    NSString *cellContent;
    NSIndexPath *indexpath;
    
}

@end

@implementation PostDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"帖子详情";
    commentArray = [NSMutableArray array];
    postdetailsArray = [NSMutableArray array];
    postimageArray = [NSMutableArray array];
    commentArray1 = [NSMutableArray array];
    commentArray2 = [NSMutableArray array];
    commentstr=[NSMutableArray array];
    imageArray = [NSMutableArray array];
    allImageArray = [NSMutableArray array];
    focusArray = [NSMutableArray array];
    strIdentifier1 = @"0";
    newviewStr = @"0";
    self.DSButton.layer.masksToBounds = YES;
    self.DSButton.layer.cornerRadius = 5;
    self.dashang.layer.masksToBounds = YES;
    self.dashang.layer.cornerRadius = 5;
    self.focusButton.layer.masksToBounds = YES;
    self.focusButton.layer.cornerRadius = 5;
    self.allCommentButton.layer.masksToBounds = YES;
    self.allCommentButton.layer.cornerRadius = 5;
    
    self.exceptionalView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ds.jpg"]];
    self.exceptionalCount.delegate =self;
    //return键改成Done键
    self.exceptionalCount.returnKeyType = UIReturnKeyDone;
    
    app=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    
    [app isConnectionAvailable];
    if ([app.Existence isEqualToString:@"1"]) {
    }else{
        NSString *poststr =[NSString stringWithFormat:@"message_id=%@",app.appmessageid];
        [self londingPath:PostdetailsURL Str:poststr];
        app.Existence = @"0";
    }
    
    self.recordView.backgroundColor = [UIColor redColor];
    self.recordView = [[FXRecordArcView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    self.recordView.delegate = self;
    self.recordView.hidden = YES;
    self.recordView.delegate = self;
    [self.holddownButton setTitle:@"按住说话" forState:UIControlStateNormal];
    [self.holddownButton addTarget:self action:@selector(btnDown) forControlEvents:UIControlEventTouchDown];
    [self.holddownButton addTarget:self action:@selector(LongPress) forControlEvents:UIControlEventTouchUpInside];
    [self.holddownButton.layer setMasksToBounds:YES];
    [self.holddownButton.layer setCornerRadius:7.0];
    
    self.textF.delegate = self;
    //return键改成Done键
    self.textF.returnKeyType =UIReturnKeyDone;
    
    self.DSButton.hidden = NO;
    
    //键盘通知
    [[ NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeContentViewPoint:)name: UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)btnDown
{
    [self.recordView startForFilePath:[self fullPathAtCache:@"record.wav"]];
    
}
- (NSString *)fullPathAtCache:(NSString *)fileName{
    NSError *error;
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSFileManager *fm = [NSFileManager defaultManager];
    if (YES != [fm fileExistsAtPath:path]) {
        if (YES != [fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
            NSLog(@"create dir path=%@, error=%@", path, error);
        }
    }
    return [path stringByAppendingPathComponent:fileName];
}
- (void)recordArcView:(FXRecordArcView *)arcView voiceRecorded:(NSString *)recordPath length:(float)recordLength{
    [self.holddownButton setTitle:@"语音评论" forState:UIControlStateNormal];
    self.textF.text = @"[语音评论]";
}
-(void)LongPress{
    [self.recordView commitRecording];
    recordUrl = [NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingString:@"record.wav"]];
}
#pragma mark - 语音帖子的加载
-(void)voviemessage{
    if ([audioTime intValue] >=10&[audioTime intValue] <=60) {
        aaaa = [audioTime intValue] - 10;
        bbbb = ([UIScreen mainScreen].bounds.size.width - 100)/50;
    }else if([audioTime intValue] >=60){
        audioTime = @"60";
        aaaa = [audioTime intValue] - 10;
        bbbb = ([UIScreen mainScreen].bounds.size.width - 100)/50;
    }else{
        aaaa = 0;
        bbbb = 0;
    }
    imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 2, 80 + aaaa * bbbb, 30)];
    wf = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];
    imgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(audioplaydeatil)];
    [imgView addGestureRecognizer:singleTap];//点击图片事件
    wf.image = [UIImage imageNamed:@"音量.png"];
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(imgView.bounds.size.width-30, 5, 30, 20)];
    lab.text = [NSString stringWithFormat:@"%@s",audioTime];
    imgView.backgroundColor = [UIColor colorWithRed:252/255.0 green:208/255.0 blue:30/255.0 alpha:1];
    CALayer * layer = [imgView layer];
    [layer setCornerRadius:8.0];
    layer.borderColor = [[UIColor grayColor] CGColor];
    layer.borderWidth = 1;
    //添加四个边阴影
    imgView.layer.shadowColor = [UIColor blackColor].CGColor;
    imgView.layer.shadowOffset = CGSizeMake(0, 0);
    imgView.layer.shadowOpacity = 0.5;
    imgView.layer.shadowRadius = 10.0;
    //给iamgeview添加阴影 < wbr > 和边框
    //添加两个边阴影
    imgView.layer.shadowColor = [UIColor blackColor].CGColor;
    imgView.layer.shadowOffset = CGSizeMake(4, 4);
    imgView.layer.shadowOpacity = 0.5;
    imgView.layer.shadowRadius = 2.0;
    [imgView addSubview:wf];
    [imgView addSubview:lab];
    [self.vovieView addSubview:imgView];
}
-(void)viewDidAppear:(BOOL)animated{
    if ([app.quickOrNot isEqualToString:@"1"]) {
        [self.textF becomeFirstResponder];
    }
}

-(void)audioplaydeatil{
    if (self.avPlay.playing) {
        [self.avPlay stop];
        [wf stopAnimating];
    return;
    }else{

        NSURL *url=[NSURL URLWithString:audiopath];
        NSData *data = [NSData dataWithContentsOfURL:url];
        AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithData:data error:nil];
        self.avPlay = player;
        [self.avPlay prepareToPlay];
        [self.avPlay play];
        wf.animationImages = [NSArray arrayWithObjects:
                                   [UIImage imageNamed:@"音量.png"],
                                   [UIImage imageNamed:@"音量2.png"],
//                                   [UIImage imageNamed:@"播放特效3.png"],
                              nil];
        wf.animationDuration = 1.0;
        wf.animationRepeatCount = 0;
        [wf startAnimating];
        self.avPlay.delegate = self;
    }
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    [wf stopAnimating];
}

- (void) changeContentViewPoint:(NSNotification *)notification{
    NSDictionary *userInfo = [notification userInfo];
    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [value CGRectValue];
    keyboard = keyboardRect.size.height;
    //    CGFloat keyBoardEndY = value.CGRectValue.origin.y;  // 得到键盘弹出后的键盘视图所在y坐标
    NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
    
    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(change:) object:nil];
    [thread start];
    //添加移动动画，使视图跟随键盘移动
    [UIView animateWithDuration:duration.doubleValue animations:^{
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationCurve:[curve intValue]];
    }];
}
-(void)change:(id)sender
{
    //线程睡眠0.2秒以实现视图延迟上弹
    [NSThread sleepForTimeInterval:0.3];
    CGAffineTransform pTransform = CGAffineTransformMakeTranslation(0, -keyboard);
    //使视图使用这个变换
    self.view.transform = pTransform;
    [UIView commitAnimations];
    
}
- (void)keyboardWillHide:(NSNotification *)notif {
    CGAffineTransform pTransform = CGAffineTransformMakeTranslation(0, 0);
    //使视图使用这个变换
    self.view.transform = pTransform;
    [UIView commitAnimations];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self hide];
}
-(void)hide{
    [self.textF endEditing:YES];
}

#pragma mark - 点击换行完成编辑
-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if (self.textF == textField || self.exceptionalCount == textField) {
        [self.textF resignFirstResponder];
        [self.exceptionalCount resignFirstResponder];
    }
    return YES;  
    
}
#pragma mark - 请求加载帖子详情信息
-(void)londingPath:(NSString *)path Str:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        postdetailsArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        [self performSelectorOnMainThread:@selector(refreshData:) withObject:postdetailsArray waitUntilDone:YES];
    }];
}

-(void)refreshData:(NSMutableArray *)sender{
    
    if (app.user_id == nil || [app.user_id isEqualToString:@""]) {
        self.dashang.hidden = YES;
        self.focusButton.hidden = YES;
    }else{
        self.dashang.hidden = NO;
    if (postdetailsArray[postdetailsArray.count-1] == [NSNull null]) {
        
        self.focusButton.hidden = NO;
        [self.focusButton setTitle:@"关注" forState:UIControlStateNormal];
    }else{
        for (NSDictionary *dic in postdetailsArray[postdetailsArray.count-1]) {
            [focusArray addObject:dic[@"focususer_id"]];
        }
        if ([focusArray containsObject:app.user_id]) {  //如果已经关注
            self.focusButton.hidden = NO;
            [self.focusButton setTitle:@"取消关注" forState:UIControlStateNormal];
        }else if([app.user_id isEqualToString:[NSString stringWithFormat:@"%@",postdetailsArray[1][0][@"user_id"]]]){  //如果是自己的帖子
            self.focusButton.hidden = YES;
            self.DSButton.hidden = YES;
        }else{  //如果没有关注
            self.focusButton.hidden = NO;
            [self.focusButton setTitle:@"关注" forState:UIControlStateNormal];
        }
    }
    }
    [self.focusButton addTarget:self action:@selector(focusAction) forControlEvents:UIControlEventTouchUpInside];
    NSString *headportrait = [NSString stringWithFormat:@"%@",postdetailsArray[0][0][@"user_headPortrait"]];
    NSURL *url=[NSURL URLWithString:headportrait];
    self.pictureClick.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    for(NSDictionary *dic in postdetailsArray[1]){
    userid = [NSString stringWithFormat:@"%@",dic[@"user_id"]];
    self.timeLabel.text=[NSString stringWithFormat:@"%@",dic[@"message_time"]];  //帖子发布时间
    self.showTime.text=[NSString stringWithFormat:@"%@",dic[@"message_showtime"]];  //帖子显示时长
    app.showTime = self.showTime.text;
    self.content.text=[NSString stringWithFormat:@"%@ \n \n",dic[@"message_content"]];   //帖子内容
    contentText = self.content.text;
        
    self.commentCount.text = [NSString stringWithFormat:@"%@",dic[@"message_comment"]];  //回帖数
    self.BrowseNumber.text = [NSString stringWithFormat:@"%@",dic[@"message_browse"]]; //浏览数
    app.commentNumber=dic[@"message_comment"];
        
    messageTag = [NSString stringWithFormat:@"%@",dic[@"message_tag"]];
    if ([messageTag isEqualToString:@"2"]) {
        self.VoiceMessages.hidden = NO;
        self.vovieView.hidden = NO;
        for (NSDictionary *ypdic in postdetailsArray[postdetailsArray.count-3]) {
            audioTime = ypdic[@"audio_time"];
            audiopath = ypdic[@"audio_path"];
    }
        //语音帖子的加载
        [self voviemessage];
    }
        //经纬度转换成地址
    CLLocationCoordinate2D coordinate;
        
    coordinate. latitude =  [[ NSString stringWithFormat : @"%@" , dic[@"message_latitude"] ] floatValue ];
        
    coordinate. longitude = [[ NSString stringWithFormat : @"%@" , dic[@"message_longitude"] ] floatValue ];
        
    CLLocation *newLocation=[[ CLLocation alloc ] initWithLatitude :coordinate. latitude longitude : coordinate. longitude ];
        
    CLGeocoder *geocoder=[[ CLGeocoder alloc ] init ];
        
    [geocoder reverseGeocodeLocation :newLocation completionHandler :^( NSArray * placemarks, NSError * error)
         
    {
            
        MKPlacemark *placemark = [placemarks objectAtIndex : 0 ];
            
        self.placeLabel.text = [ NSString stringWithFormat : @"%@%@" ,  placemark. subLocality , placemark.thoroughfare];
            
        }];
    }
    if (postdetailsArray[postdetailsArray.count-2] == [NSNull null]) {
    }else{
        commentArray1 = postdetailsArray[postdetailsArray.count-2];
        for (NSDictionary *dic in commentArray1) {
            Comment *co = [[Comment alloc]init];
            co.comment_content = dic[@"comment_content"];
            co.comment_time = dic[@"comment_time"];
            co.comment_heardPortrait = dic[@"comment_headPortrait"];
            co.comment_identifier = dic[@"comment_identifier"];
            co.user_phone = dic[@"user_phone"];
            co.comment_image = dic[@"comment_image"];
            co.comment_audio = dic[@"comment_audio"];

            [commentArray2 addObject:co];
        }
        [self.tableView reloadData];
    }
    
    if ([messageTag isEqualToString:@"0"]) { //纯文字或者文字图
        if (postdetailsArray[2] == [NSNull null]) {
        }else{
            index = (int)self.content.text.length;
            postimageArray = postdetailsArray[2];
            allCount = (int)postimageArray.count;
            if (postimageArray.count>=3) {
                imgcount = 3;
            }else{
                imgcount = (int)postimageArray.count;
            }
            for (int i=0; i<imgcount; i++) {

            NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",postdetailsArray[2][i][@"image_path"]]];
            UIImage *immmm = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
                [imageArray addObject:immmm];
            ImageCompression *ima = [[ImageCompression alloc]init];
            [ima OriginImage:immmm scaleToSize:CGSizeMake((self.content.size.width-15)/3, (self.content.size.width-15)/3)];
             
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:self.content.attributedText];
            NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
            textAttachment.image = ima.scaledImage;
            NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment] ;
            [string insertAttributedString:textAttachmentString atIndex:index];//index为用户指定要插入图片的位置
            index++;
                
                NSAttributedString *black = [[NSAttributedString alloc]initWithString:@"\n"];
                [string appendAttributedString:black];
                
            self.content.attributedText = string;
              
            }
            CGSize deSize = [self.content sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width,CGFLOAT_MAX)];
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(self.content.size.width-90, deSize.height-30, 80, 20)];
            button.backgroundColor = [UIColor whiteColor];
            [button.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:14]];
            [button setTitle:@"查看大图" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(ImageText) forControlEvents:UIControlEventTouchUpInside];
            [self.content addSubview:button];
            app.appimageArray = postdetailsArray[2];
        }
        self.content.hidden = NO;
    }else if ([messageTag isEqualToString:@"1"]){  //纯图片
        index = 0;
        postimageArray = postdetailsArray[2];
        allCount = (int)postimageArray.count;
        if (postimageArray.count>=3) {
            imgcount = 3;
        }else{
            imgcount = (int)postimageArray.count;
        }
        CGFloat width=self.scrollImage.bounds.size.height-20;
        CGFloat height=self.scrollImage.bounds.size.height-20;
        for (int i = 0; i < imgcount; i++) {
            NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",postdetailsArray[2][i][@"image_path"]]];
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
            [imageArray addObject:image];
        }
        for (int j=0; j<imageArray.count; j++) {
        
            UIImageView *imageView=[[UIImageView alloc] initWithImage:imageArray[j]];
            [imageView setFrame:CGRectMake(j*width+j*10, 0, width, height)];
            [self.scrollImage addSubview:imageView];
            imageView.userInteractionEnabled = YES;
            UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ImageText)];
            [imageView addGestureRecognizer:gest];
            
        }
        [self.scrollImage setBounces:NO];
        //设置水平方向的滚动条:
        [self.scrollImage setShowsHorizontalScrollIndicator:NO];
        //设置ScrollView的总体的宽度(关键)：
        [self.scrollImage setContentSize:CGSizeMake((imageArray.count) * (width+10), height)];
        //设置分页:
        [self.scrollImage setPagingEnabled:YES];
        
        self.content.hidden = YES;
        self.scrollImage.hidden = NO;
        app.appimageArray = postdetailsArray[2];
    }
    // 计时器
    NSTimer *countdownTimer=[[NSTimer alloc]init];
    countdownTimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(TheCountDown) userInfo:nil repeats:YES];
}
-(void)focusAction{
    NSString *string = [NSString stringWithFormat:@"myuser_id=%@&heuser_id=%@",app.user_id,postdetailsArray[1][0][@"user_id"]];
    if ([self.focusButton.titleLabel.text isEqualToString:@"关注"]) {
        [self focusPath:myFocusURL Str:string];
        [self.focusButton setTitle:@"取消关注" forState:UIControlStateNormal];
    }else if([self.focusButton.titleLabel.text isEqualToString:@"取消关注"]){
        [self focusPath:myFocuscancelURL Str:string];
        [self.focusButton setTitle:@"关注" forState:UIControlStateNormal];
    }
}
-(void)focusPath:(NSString *)path Str:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        focusStr =[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [self performSelectorOnMainThread:@selector(focusData) withObject:focusStr waitUntilDone:YES];
    }];
}
-(void)focusData{
}
#pragma mark - 图文时候点击大图
-(void)ImageText{
    self.navigationController.navigationBarHidden=YES;
    CGFloat width = 0.0;
    bigView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    bigView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:bigView];
    
    if ([messageTag isEqualToString:@"0"]) {
        bigScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height-80)];
        [self.view addSubview:bigScroll];
    }else{
        bigScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height)];
        [self.view addSubview:bigScroll];
    }
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, [UIScreen mainScreen].bounds.size.height-80, [UIScreen mainScreen].bounds.size.width-40, 60)];
    [bigView addSubview:textView];
    textView.textColor = [UIColor whiteColor];
    textView.backgroundColor = [UIColor colorWithRed: 255/255.0  green: 255/255.0  blue: 255/255.0  alpha: 0];
    textView.editable = NO;
    textView.text = contentText;
    
    for (int j=0; j<allCount; j++) {
        ImageCompression *ima = [[ImageCompression alloc]init];
        NSURL *url = [NSURL URLWithString:postdetailsArray[2][j][@"image_path"]];
        UIImage *bigpic = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        if (bigpic.size.width<[UIScreen mainScreen].bounds.size.width) {
            width = bigpic.size.width ;
        }else{
            width = [UIScreen mainScreen].bounds.size.width;
        }
        [ima OriginImage:bigpic scaleToSize:CGSizeMake(width, bigpic.size.height/bigpic.size.width*width)];
        UIImageView *imageView=[[UIImageView alloc] initWithImage:ima.scaledImage];
        [imageView setFrame:CGRectMake(j*[UIScreen mainScreen].bounds.size.width+([UIScreen mainScreen].bounds.size.width-width)/2, (([UIScreen mainScreen].bounds.size.height-60)-bigpic.size.height/bigpic.size.width*width)/2, width,  bigpic.size.height/bigpic.size.width*width)];
        [bigScroll addSubview:imageView];
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bigCancelClick)];
        [imageView addGestureRecognizer:gest];

    }
    [bigScroll setBounces:NO];
    //设置水平方向的滚动条:
    [bigScroll setShowsHorizontalScrollIndicator:NO];
    
    if ([messageTag isEqualToString:@"0"]) {
        //设置ScrollView的总体的宽度(关键)：
        [bigScroll setContentSize:CGSizeMake(allCount * width, [UIScreen mainScreen].bounds.size.height-80)];
    }else{
        [bigScroll setContentSize:CGSizeMake(allCount * width, [UIScreen mainScreen].bounds.size.height)];
    }
    
    //设置分页:
    [bigScroll setPagingEnabled:YES];
    
}


#pragma mark - 退出大图
-(void)bigCancelClick{
    self.navigationController.navigationBarHidden=NO;
    [bigScroll removeFromSuperview];
    [bigView removeFromSuperview];
}
-(void)TheCountDown{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];//设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    [formatter setTimeZone:timeZone];
    NSDate *datenow = [NSDate date];
    NSDateFormatter * dm = [[NSDateFormatter alloc]init];
    //指定输出的格式   这里格式必须是和上面定义字符串的格式相同，否则输出空
    [dm setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSDate * newdate = [dm dateFromString:self.timeLabel.text];
    
    int showtimeint = [self.showTime.text intValue];
    int dd = [newdate timeIntervalSince1970] + showtimeint*60 - (long)[datenow timeIntervalSince1970];
    
    if (dd <= 0) {
        self.theRestTime.text = @"00:00:00";
    }else{
    int h = (dd / 60 / 60);
    int m = (dd - h * 60 * 60) / 60;
    int s = ((dd - h * 60 * 60 - m * 60));
    self.theRestTime.text=[NSString stringWithFormat:@"%d:%d:%d",h,m,s];
    dd --;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark - 获取当前时间
-(void)getTime{
    NSDateFormatter *fomatter=[[NSDateFormatter alloc]init];
    [fomatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *nowTime=[fomatter stringFromDate:[NSDate date]];
    currentTime=nowTime;
}
#pragma mark - 评论回复的发送按钮事件
- (IBAction)sendButton:(id)sender {
    self.textF.enabled = YES;
    [self.textF resignFirstResponder];
    //获取当前时间
    [self getTime];
        if (app.user_id==nil||[app.user_id isEqualToString:@""]) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您尚未登陆" delegate:self cancelButtonTitle:@"去登陆" otherButtonTitles:@"取消", nil];
            _alert=alert;
            [alert show];
        }
        else{
            if ([self.textF.text isEqualToString:@""]) {
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请输入评论内容" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
                [alert show];
            }
            else{
            if ([strIdentifier1 isEqualToString:@"1"]) {
                Content = [NSString stringWithFormat:@"%@%@",contentStr,self.textF.text];
                NSString *poststr =[NSString stringWithFormat:@"user_phone=%@&message_id=%@&comment_content=%@&comment_time=%@&comment_headPortrait=%@&comment_identifier=%@",app.appPersonArray[0][@"user_phone"],app.appmessageid,Content,currentTime,app.appPersonArray[0][@"user_headPortrait"],strIdentifier1];
                [self loadingPath2:commentURL Str2:poststr];
                strIdentifier1 = @"0";
                NSString *poststr1 =[NSString stringWithFormat:@"message_id=%@",app.appmessageid];
                //评论数 +1
                [self londingPath1:commentcountURL Str1:poststr1];
                self.textF.text = @"";
                [self hide];
            }
            else{
                NSString *poststr1 =[NSString stringWithFormat:@"user_phone=%@&message_id=%@&comment_content=%@&comment_time=%@&comment_headPortrait=%@&comment_identifier=%@",app.appPersonArray[0][@"user_phone"],app.appmessageid,self.textF.text,currentTime,app.appPersonArray[0][@"user_headPortrait"],strIdentifier1];
                //评论请求
                [self loadingPath2:commentURL Str2:poststr1];
                    if ([self.textF.text isEqualToString:@"图片评论"]) {
                        [self performSelector:@selector(csImage:)  withObject:img afterDelay:0.5];
                }
                strIdentifier1 = @"0";
                NSString *poststr =[NSString stringWithFormat:@"message_id=%@",app.appmessageid];
                
                //评论数 +1
                [self londingPath1:commentcountURL Str1:poststr];
                self.textF.text = @"";
                [self hide];
                    }
                }
        }
    
    self.textF.placeholder = @"";
}
-(void)audioupload{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:[self fullPathAtCache:@"record.wav"]]];
    NSURL *url = [[NSURL alloc]initWithString:audioURL];
    ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
    [request addData:data withFileName:@"record.wav" andContentType:@"audio/wav" forKey:@"audio_path"];
    //添加普通的请求参数
    [request setPostValue:commentID forKey:@"comment_id"];
    [request setDelegate:self];
    [request startAsynchronous];
    self.holddownButton.hidden = YES;
    self.QXbutton.hidden = YES;
    self.jiaButton.hidden = NO;
    newviewStr = @"0";
}

#pragma mark - 返回tableview的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    //判断评论数量，超过十条，“查看全部评论与回复”按钮显示，否则隐藏
    if (commentArray2.count<10) {
        self.allCommentButton.hidden=YES;
    }else{
        self.allCommentButton.hidden=NO;
    }
    return commentArray2.count;

}

#pragma mark - 返回tableview的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
      CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
      return 1  + size.height;
}
#pragma mark - cell的内容加载
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UINib *nib=[UINib nibWithNibName:@"commCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"commCell"];
    
    static NSString *cellIdentifier=@"commCell";
    cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    Comment *comm = commentArray2[indexPath.row];
    cell.comment_Time.text=[NSString stringWithFormat:@"%@",comm.comment_time];
    
    //把手机号码的中间五位换成 *
    NSString *star=[comm.user_phone stringByReplacingCharactersInRange:NSMakeRange(3, 5) withString:@"***"];
    cell.user_phone.text = [NSString stringWithFormat:@"%@",star];
    
    NSURL *url = [NSURL URLWithString:comm.comment_heardPortrait];
    cell.HeadPortrait.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    
    cell.floor.text=[NSString stringWithFormat:@"%ld",(unsigned long)indexPath.row+1];
    strIdentifier=[NSString stringWithFormat:@"%@",comm.comment_identifier];
    
    cellContent = [NSString stringWithFormat:@"%@",comm.comment_content];
    
    
    if ([strIdentifier isEqualToString:@"0"]) {
        
        if ([cellContent rangeOfString:@"[图片评论]"].location !=NSNotFound) {
            cell.comment_Content.userInteractionEnabled = YES;
            cell.audioview.hidden = YES;
            cell.comment_Content.hidden = NO;
            NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",comm.comment_image]];
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
            cell.image = image;
            ImageCompression *ima = [[ImageCompression alloc]init];
            [ima OriginImage:image scaleToSize:CGSizeMake(30, 30)];
            
            NSTextAttachment *textAttach = [[NSTextAttachment alloc] init];
            textAttach.image = ima.scaledImage;
            
            NSAttributedString *strA = [NSAttributedString attributedStringWithAttachment:textAttach];
            
            cell.comment_Content.attributedText = strA;
            cell.tagStr = @"1";
            
        }else if([comm.comment_content rangeOfString:@"[语音评论]"].location !=NSNotFound) {
            cell.audiourl = [NSURL URLWithString:comm.comment_audio];
            cell.audioview.hidden = NO;
            cell.comment_Content.hidden = YES;
            cell.comment_Content.userInteractionEnabled = NO;
        }else{
            cell.comment_Content.userInteractionEnabled = NO;
            cell.audioview.hidden = YES;
            cell.comment_Content.hidden = NO;
            cell.comment_Content.text=[NSString stringWithFormat:@"%@",comm.comment_content];
        }
    }
    else{
        //部分字体变颜色
        NSRange range1=[cellContent rangeOfString:@":"];
        NSString *str = [cellContent substringWithRange:NSMakeRange(0, range1.location+1)];
        
        NSMutableAttributedString *colorStr1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",str]];
        [colorStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,range1.location+1)];//长度
        NSMutableAttributedString *colorStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",cellContent]];
        NSRange range=[cellContent rangeOfString:@":"];
        [colorStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,range.location+1)];//长度
        
        
        
        if ([cellContent rangeOfString:@"[图片评论]"].location !=NSNotFound) {
            cell.comment_Content.userInteractionEnabled = YES;
            cell.audioview.hidden = YES;
            cell.comment_Content.hidden = NO;
            NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",comm.comment_image]];
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
            cell.image = image;
            ImageCompression *ima = [[ImageCompression alloc]init];
            [ima OriginImage:image scaleToSize:CGSizeMake(30, 30)];
            // 1> 生成文本附件
            NSTextAttachment *textAttach = [[NSTextAttachment alloc] init];
            textAttach.image = ima.scaledImage;
            
            // 2> 使用文本附件创建属性文本
            NSAttributedString *strA = [NSAttributedString attributedStringWithAttachment:textAttach];
            
            [colorStr1 appendAttributedString:strA];
            
            cell.comment_Content.attributedText = colorStr1;
            
            cell.tagStr = @"1";

        }else if ([comm.comment_content rangeOfString:@"[语音评论]"].location !=NSNotFound) {
            cell.audiourl = [NSURL URLWithString:comm.comment_audio];
            cell.audioview.hidden = NO;
            cell.comment_Content.hidden = YES;
            cell.comment_Content.userInteractionEnabled = NO;
        }else{
            cell.audioview.hidden = YES;
            cell.comment_Content.hidden = NO;
            cell.comment_Content.attributedText = colorStr;
            cell.comment_Content.userInteractionEnabled = NO;
        }
        
    }
    

    
    return cell;
}

#pragma mark - 评论内容的所在cell的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    indexpath = indexPath;
    
    if (app.user_id==nil||[app.user_id isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您尚未登陆" delegate:self cancelButtonTitle:@"去登陆" otherButtonTitles:@"取消", nil];
        _alert=alert;
        [alert show];
    }else{
        NSString *hf = @"回复";
        NSString *l = @"楼:";
        contentStr = [NSString stringWithFormat:@"%@%ld%@",hf,(unsigned long)indexPath.row+1,l];
        strIdentifier1 = @"1";
        self.textF.placeholder = [NSString stringWithFormat:@"%@",contentStr];
        self.cancelButton.hidden = NO;
        [self.cancelButton addTarget:self action:@selector(CancelClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self.textF resignFirstResponder];
    }
}

#pragma mark - 取消回复
-(void)CancelClick{
    self.cancelButton.hidden = YES;
    strIdentifier1 = @"0";
    self.textF.placeholder = @"";
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"您已取消回复" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    [self.tableView deselectRowAtIndexPath:indexpath animated:YES];
    
}

#pragma mark - 评论数量＋1
-(void)londingPath1:(NSString *)path Str1:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        commcount = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [self performSelectorOnMainThread:@selector(refreshData1:) withObject:commcount waitUntilDone:YES];
    }];
}
-(void)refreshData1:(NSMutableArray *)sender{
}



#pragma mark - "评论"请求数据加载
-(void)loadingPath2:(NSString *)path Str2:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        commentstr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        [self performSelectorOnMainThread:@selector(refreshDatacomment:) withObject:commentstr waitUntilDone:YES];
    }];
}
-(void)refreshDatacomment:(NSMutableArray *)sender{
    if ([messageTag isEqualToString:@"0"]) {
        news_content = [self.content.text substringToIndex:10];
    }else if ([messageTag isEqualToString:@"1"]){
        news_content = @"[图片帖子]";
    }else{
        news_content = @"[语音帖子]";
    }
    if ([userid isEqualToString:app.user_id]) {
    }else{
        NSLog(@"---%@---%@",userid,app.user_id);
    NSString *poststr =[NSString stringWithFormat:@"user_id=%@&message_id=%@&content=%@",userid,app.appmessageid,news_content];
    [self newsPath:newsURL Str:poststr];
    }
    for (NSDictionary *dic1 in commentstr){
        c = [[Comment alloc]init];
        commentID = dic1[@"comment_id"];
        c.comment_content = dic1[@"comment_content"];
        c.comment_time = dic1[@"comment_time"];
        c.comment_heardPortrait = dic1[@"comment_headPortrait"];
        c.comment_identifier=dic1[@"comment_identifier"];
        c.user_phone = dic1[@"user_phone"];
        c.comment_image = dic1[@"comment_image"];
        c.comment_audio = dic1[@"comment_audio"];
        [commentArray2 addObject:c];
    }
    if ([c.comment_content rangeOfString:@"[图片评论]"].location !=NSNotFound) {
        [self performSelector:@selector(csImage:)  withObject:img afterDelay:0.5];
    }
    if ([self.holddownButton.titleLabel.text isEqualToString:@"语音评论"]) {
        [self audioupload];
    }
    showTimeStr = [ NSString stringWithFormat:@"%d",([self.showTime.text intValue]+1)];
    self.showTime.text=showTimeStr;
    app.showTime = showTimeStr;
    if (commentArray2.count>10) {
    }else{
    [self.tableView reloadData];
    }
}
-(void)newsPath:(NSString *)path Str:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        usernews = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [self performSelectorOnMainThread:@selector(refreshDatanews:) withObject:usernews waitUntilDone:YES];
    }];
}
-(void)refreshDatanews:(NSString *)sender{
}
#pragma mark - 查看所有评论回复按钮事件
- (IBAction)AllCommentButton:(id)sender {
    //跳转全部评论回复按钮
    AllCommentViewController *allComment=[self.storyboard instantiateViewControllerWithIdentifier:@"allCommentVC"];
    [self.navigationController pushViewController:allComment animated:YES];
}
- (IBAction)voice:(id)sender {
    self.newview.hidden = YES;
    self.holddownButton.hidden = NO;
    self.QXbutton.hidden = NO;
    self.jiaButton.hidden = YES;
}

- (IBAction)cam:(id)sender {
    self.newview.hidden = YES;
    [self photoChoose];
}

- (IBAction)HoldDown:(id)sender {
}

- (IBAction)pic:(id)sender {
    if ([newviewStr isEqualToString:@"0"]) {
        self.newview.hidden = NO;
        newviewStr = @"1";
    }else{
        self.newview.hidden = YES;
        newviewStr = @"0";
    }
}
-(void)photoChoose{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"请选择文件来源" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"本地相册",nil];
    [actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0://照相机
        {   if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.allowsEditing = NO;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:imagePicker animated:YES completion:nil];
        }else{
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"没有相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
            
        }
            break;
            
        case 1://本地相簿
        {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.allowsEditing = NO;
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            [self presentViewController:imagePicker animated:YES completion:nil];
        }
            break;
            break;
            
        default:
            break;
    }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.textF.text=@"[图片评论]";
    img = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self.textF resignFirstResponder];
    self.textF.enabled = NO;
    [picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)csImage:(UIImage *)image {
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imageFilePath = [documentsDirectory stringByAppendingPathComponent:@"selfPhoto.jpg"];
    success = [fileManager fileExistsAtPath:imageFilePath];
    if(success) {
        success = [fileManager removeItemAtPath:imageFilePath error:&error];
    }
    
    ImageCompression *imageC = [[ImageCompression alloc]init];
    [imageC imageByScalingToMaxSize:image];
    [UIImageJPEGRepresentation(imageC.newimage, 1.0f) writeToFile:imageFilePath atomically:YES];//写入文件
    UIImage *Image=[UIImage imageWithContentsOfFile:imageFilePath];//写入文件
    self.photoImage=Image;

    NSData *data = UIImageJPEGRepresentation(self.photoImage, 0.5);
    NSURL *url=[NSURL URLWithString:commentImageURL];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    request.delegate = self;
    [request setData:data  withFileName:@"tmp.jpg" andContentType:@"image/jpg" forKey:@"comment_image"];
    [request setPostValue:commentID forKey:@"comment_id"];
    [request setTag:3];
    [request startAsynchronous];
}
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data{
    NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSUTF8StringEncoding error:nil];
    NSString *str1=dic[@"key"];
    
    if ([str1 isEqualToString:@"success"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"touxiangAPI" object:nil];
    }
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -赏按钮提交
- (IBAction)exceptionalSubmit:(id)sender {
    
    if ([self.exceptionalCount.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示：" message:@"客官，您还没有给积分呐！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else{
    
    NSString *string = [NSString stringWithFormat:@"myuser_id=%@&heuser_id=%@&dscount=%@",app.user_id,userid,self.exceptionalCount.text];
    [self DSPath:DSURL Str:string];
    }
}

#pragma mark - 赏 的事件
- (IBAction)exceptionalAction:(id)sender {
    self.exceptionalView.hidden = NO;
}

#pragma mark - 打赏请求数据
-(void)DSPath:(NSString *)path Str:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        DSStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [self performSelectorOnMainThread:@selector(refreshDataDS:) withObject:DSStr waitUntilDone:YES];
    }];
}
-(void)refreshDataDS:(NSString *)sender{
    if ([sender isEqualToString:@"0"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示：" message:@"很遗憾，您的积分不足以打赏" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else{
    self.exceptionalView.hidden = YES;
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"恭喜：" message:@"帖主已收到您的打赏,谢谢您的慷慨" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    }
}
- (IBAction)gbButton:(id)sender {
    self.exceptionalView.hidden = YES;
}
- (IBAction)QX:(id)sender {
    [self.holddownButton setTitle:@"按住说话" forState:UIControlStateNormal];
    self.holddownButton.hidden = YES;
    self.jiaButton.hidden = NO;
    self.QXbutton.hidden = YES;
    newviewStr = @"0";
}
@end
